<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>3：实现类似挑选人的功能，点击挑选按钮后，开始随机显示人名（提前定义在数组中）再次点击按钮，停止运行，
			并显示被选中的人名，要保证下次不会再次抽中此人</title>
			<style>
				
			</style>
	</head>
	<body>
		<div id="d1">
			<div id="d2"></div>
			<span>幸运儿：</span><p id="d3"></p>
			
			<button id="d4" onclick="choose()">开始挑选</button>
		</div>
		<script>
			var ti;
			var c;
			var a = document.getElementById("d2");
			var b = document.getElementById("d3");
			var d = document.getElementById("d4");
			var na = ["潘总", "翟总", "黄总", "蒋委员", "李总", "汤总", "小王", "丁总", "陈总", "朱总"];
			function choose() {
				if (d.innerHTML == "开始挑选") {
					c = setInterval(function() {
						var index = parseInt(Math.random() * na.length);
						a.innerHTML = na[index]
					}, 10);
					d.innerHTML = "结束滚动";
				} else {
					clearInterval(c);
					b.innerHTML=a.innerHTML;
					var e=na.indexOf(a.innerHTML);
					console.log(e)
					na.splice(e,1);
					console.log(na.join(","))
					d.innerHTML = "开始挑选";
				}
			}
		</script>
	</body>
</html>
